package com.bbx.taxi.client.Task;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Handler;

import com.bbx.androidapi.util.ToastUtil;
import com.bbx.api.sdk.model.official.passanger.Officail_ComboBuild;
import com.bbx.api.sdk.model.official.passanger.Official_MonthlyBuild;
import com.bbx.api.sdk.model.official.passanger.Official_MonthlyBuild;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_Combo;
import com.bbx.api.sdk.model.official.passanger.Return.Officail_TC;
import com.bbx.api.sdk.model.official.passanger.Return.Official_Star;
import com.bbx.api.sdk.net.base.JsonBuild;
import com.bbx.api.sdk.net.official.passanger.Officail_ComboNet;
import com.bbx.api.sdk.net.official.passanger.Official_MonthlyNet;
import com.bbx.api.sdk.net.official.passanger.Official_StarNet;
import com.bbx.api.sdk.net.official.passanger.Official_TCNet;
import com.bbx.taxi.client.Bean.Value;
import com.bbx.taxi.client.Bean.Attribute.MainAttribute;
import com.bbx.taxi.client.Task.BaseAsyncTask;
import com.bbx.taxi.client.Task.MyOperateTask.OnOperateStatusListener;
import com.bbx.taxi.client.MyApplication;
import com.bbx.taxi.official.R;
/** 
 * @Path com.bbx.taxi.client.Task.MyMonthlyBuild.java
 * @Author 严旭文
 * @Date 2016-4-8 下午12:38:37
 * @Company 蓝海（福建）信息技术有限公司
 * @Description
 * 月结支付
 */
public class MyMonthlyTask {
	public static int STATUS_SUCCESS=0;
	public static int STATUS_FAIL=-1;
	private Activity context;
	public static MyMonthlyTask instance;
	public MonthlyTask mMonthlyTask;
	public interface OnMonthlyFinishListener {
		/**
		 *status 0为成功
		 */
		public void onMonthlyFinish(int status);
	}

	static OnMonthlyFinishListener mOnMonthlyFinishListener = null;

	public static void setOnMonthlyFinishListener(OnMonthlyFinishListener l) {
		mOnMonthlyFinishListener = l;
	}
	public static MyMonthlyTask getInstance(Activity context,String order_id) {
		instance = new MyMonthlyTask(context,order_id);
		return instance;
	}
	public MyMonthlyTask(Activity context,String order_id) {
		this.context = context;
		setMonthly(order_id);
	
	}
	/**
	 * Monthly制
	 */
	public void setMonthly(String order_id) {
		Official_MonthlyBuild mOfficial_MonthlyBuild=new Official_MonthlyBuild(context);
		mOfficial_MonthlyBuild.passenger_id=MyApplication.getInstance().getUid();
		mOfficial_MonthlyBuild.order_id=order_id;
		MonthlyTask mMonthlyTask=new MonthlyTask(context, mOfficial_MonthlyBuild);
		mMonthlyTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
	}
	private class MonthlyTask extends BaseAsyncTask {

		private Official_MonthlyBuild mOfficial_MonthlyBuild;

		public MonthlyTask(Activity context, Official_MonthlyBuild mOfficial_MonthlyBuild) {
			super(context,true);
			this.mOfficial_MonthlyBuild = mOfficial_MonthlyBuild;
		}

		@Override
		public void onSuccess(Object object) {
			if (object != null) {
				   if(mOnMonthlyFinishListener!=null)mOnMonthlyFinishListener.onMonthlyFinish(STATUS_SUCCESS);
			}else{
				ToastUtil.showToast(context, R.string.no_network);
				if(mOnMonthlyFinishListener!=null)mOnMonthlyFinishListener.onMonthlyFinish(STATUS_FAIL);
			}
		}

		@Override
		public void onFailed(int status, String msg) {
			try {
				JSONObject jso=new JSONObject(msg);
				ToastUtil.showToast(context, jso.getString("message"));
			} catch (JSONException e) {
				e.printStackTrace();
			}
			if(mOnMonthlyFinishListener!=null)mOnMonthlyFinishListener.onMonthlyFinish(STATUS_FAIL);
		}

		@Override
		protected Object doInBackground(Object... params) {
			// TODO Auto-generated method stub
			String json = new JsonBuild().setModel(mOfficial_MonthlyBuild).getJson();
			return new Official_MonthlyNet(context, json);
		}
	}

}
